From b95141040f785042cdb7f9d926099c36691704c4 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Fri, 18 Dec 2015 12:27:08 +0000 Subject: [PATCH] Only treat missing crate lists as empty The motivation is that errors other than "file not found" could lead to the file being overwritten by an empty config, e.g. if the `open` call is interrupted and returns `EINTR`, then this code would read an empty config and write it back later on. This can probably happen for other errors as well (`ENFILE`, ...). --- src/cargo/ops/cargo_install.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index dc0223380..dfe9ea361 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -4,6 +4,7 @@ use std::env; use std::ffi::OsString; use std::fs::{self, File}; use std::io::prelude::*; +use std::io; use std::path::{Path, PathBuf}; use toml; @@ -222,7 +223,15 @@ fn read_crate_list(path: &Path) -> CargoResult { let metadata = path.join(".crates.toml"); let mut f = match File::open(&metadata) { Ok(f) => f, - Err(..) => return Ok(CrateListingV1 { v1: BTreeMap::new() }), + Err(e) => { + if e.kind() == io::ErrorKind::NotFound { + return Ok(CrateListingV1 { v1: BTreeMap::new() }); + } + return Err(e).chain_error(|| { + human(format!("failed to open crate metadata at `{}`", + metadata.display())) + }); + } }; (|| -> CargoResult<_> { let mut contents = String::new(); -- 2.30.2